package com.koicarp.agent.example.chatmemery;

import org.springframework.stereotype.Service;

import java.util.ArrayList;
import java.util.List;

/**
 * @Author: liuxia
 * @CreateTime: 2025/9/14 下午3:09
 * @Description: 聊天信息实现类
 */
@Service
public class ChatMessageServiceImpl implements  ChatMessageService {

    /**
     * 假设这是数据库
     */
    private List<CustomChatMessage> messages = new ArrayList<>();

    @Override
    public List<CustomChatMessage> getMessageListById(Integer userId) {
        return messages.stream().filter(f -> f.getUserId().equals(userId)).toList();
    }

    @Override
    public boolean save(Integer userId, Integer type, String message) {
        CustomChatMessage msg = CustomChatMessage.builder()
                .userId(userId)
                .type(type)
                .message(message)
                .build();
        messages.add(msg);
        return true;
    }

    @Override
    public boolean delByUserId(Integer userId) {
        messages.removeIf(f -> f.getUserId().equals(userId));
        return true;
    }
}
